package ink.lovejinhu.leetcode;

/**
 * @Author: jin
 * @Date: 2021/9/10 21:31
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0905 {
    public int[] sortArrayByParity(int[] nums) {
/**
 * i ou  j ou
 * i ou   j ji
 * i ji   j  ou
 * i ji  j  ji
 *
 */
        for (int i = 0, j = nums.length - 1; i < j; ) {
            if (nums[i] % 2 == 0 && nums[j] % 2 == 0) {
                i++;
            } else if (nums[i] % 2 == 0 && nums[j] % 2 != 0) {
                i++;
                j--;
            } else if (nums[i] % 2 != 0 && nums[j] % 2 == 0) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
                i++;
                j--;
            } else {
                j--;
            }


        }
        return nums;
    }
}
